<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
	<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload.css" />
	<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload-ui.css" />
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/vendor/jquery.ui.widget.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-ui.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.iframe-transport.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-process.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
</head>
<body>
	<div class="modal-dialog" role="document" style="width:800px;">
	    <div class="modal-content">
	        <div class="modal-header">
	            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	            <h4 class="modal-title" id="exampleModalLabel"><if condition="$id">修改空间<else/>添加空间</if></h4>
	        </div>
	        <form class="form-horizontal" style="padding:4%;height:500px;overflow-y:auto;" id="spaceForm">
				<input type="hidden" name="token" value="{$formToken}">
	        	<input type="hidden" name="id" value="{$id}"/>
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">基本信息</h3>
					</div>
					<div class="panel-body">
						<div class="form-group">
							<label class="control-label col-sm-2">空间名称:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="name" value="{$space.name}" placeholder="请输入空间名称">
							</div>
							<label class="control-label col-sm-2">运营面积:</label>
							<div class="col-sm-4">
								<div class="input-group">
									<input type="text" class="form-control" name="area" value="{$space.area}" placeholder="请输入运营面积">
									<div class="input-group-addon">M&sup2;</div>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">开放工位价格:</label>
							<div class="col-sm-4">
								<div class="input-group">
									<input type="text" class="form-control" name="station_open_price" value="{$space.station_open_price}" placeholder="请输入开放工位价格">
									<div class="input-group-addon">元</div>
								</div>
							</div>
							<label class="control-label col-sm-2">封闭工位价格:</label>
							<div class="col-sm-4">
								<div class="input-group">
									<input type="text" class="form-control" name="station_close_price" value="{$space.station_close_price}" placeholder="请输入封闭工位价格">
									<div class="input-group-addon">元</div>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">空间地址:</label>
							<div class="col-sm-3">
								<select class="form-control" name="province" id="province">
									<foreach name="province" item="prov">
										<option value="{$prov.id}" <if condition="$space['province'] eq $prov['id']">selected</if>>{$prov.name}</option>
									</foreach>
								</select>
							</div>
							<div class="col-sm-3">
								<select class="form-control" name="city" id="city">

								</select>
							</div>
							<div class="col-sm-3">
								<select class="form-control" name="county" id="county">

								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">详细地址:</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="address" value="{$space.address}" placeholder="请输入空间详细地址">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">联系电话:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="phone" value="{$space.phone}" placeholder="请输入空间联系电话">
							</div>
						</div>
					</div>
				</div>

				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">财务信息</h3>
					</div>
					<div class="panel-body">
						<div class="form-group">
							<div class="col-sm-6">
								<p>含税收款账户</p>
							</div>
							<div class="col-sm-6">
								<p>不含税收款账户</p>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">账户名:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="account_name_tax" value="{$space.account_name_tax}" placeholder="请输入含税收款账户名">
							</div>
							<label class="control-label col-sm-2">账户名:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="account_name" value="{$space.account_name}" placeholder="请输入不含税收款账户名">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">账号:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="bank_card_id_tax" value="{$space.bank_card_id_tax}" placeholder="请输入含税收款账号">
							</div>
							<label class="control-label col-sm-2">账号:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="bank_card_id" value="{$space.bank_card_id}" placeholder="请输入不含税收款账号">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">开户行:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="bank_name_tax" value="{$space.bank_name_tax}" placeholder="请输入含税收款账户开户行">
							</div>
							<label class="control-label col-sm-2">开户行:</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="bank_name" value="{$space.bank_name}" placeholder="请输入不含税收款账户开户行">
							</div>
						</div>
					</div>
				</div>
	        </form>
	        <div class="modal-footer">
	            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
	            <button type="button" id="save" class="btn btn-primary">保存</button>
	        </div>
	    </div>
	</div>
    
	<script type="text/javascript">
		var webRoot = "__ROOT__";
		var city = "{$space.city}";
        var county = "{$space.county}";
		$(function(){
			$("#save").bind("click",doSave);
            $("#province").bind("change",chooseProvince);
            $("#city").bind("change",chooseCity);
            $("#province,#city").change();
		});
		
		var commitFlag = false;
		function doSave(){
			if(commitFlag){
				common.alert("提示","请勿重复提交");
				return;
			}
			commitFlag = true;
			if(!validateForm()){
				commitFlag = false;
				return false;
			}
			$.ajax({
                url: "{:U('Admin/Space/Spaces/doSave')}",
                type: "post",
                dataType: "json",
                data: $("#spaceForm").serialize(),
                success: function (data) {
                    if(data.status){
                    	common.alert("提示",data.msg,function(){
                            common.reload();
                        });
                    }else{
                    	commitFlag = false;
                    	common.alert("提示",data.msg);
                    }
                }
            });
		}

        function chooseProvince() {
            var pid = $(this).val();
            $("#city,#county").empty();
            $.ajax({
                url: "{:U('Admin/Space/Spaces/getRegionByPid')}",
                type: "post",
                dataType: "json",
                data: {pid: pid},
                success: function (data) {
                    var html = '';
                    $.each(data,function (index,item) {
                        var selected = (city == item.id) ? " selected" : "";
                        html += '<option value="'+item.id+'"'+selected+'>'+item.name+'</option>';
                    });
                    $("#city").html(html).change();
                }
            });
        }

		function chooseCity() {
			var pid = $(this).val();
            $("#county").empty();
            $.ajax({
                url: "{:U('Admin/Space/Spaces/getRegionByPid')}",
                type: "post",
                dataType: "json",
                data: {pid: pid},
                success: function (data) {
                    var html = '';
                    $.each(data,function (index,item) {
                        var selected = (county == item.id) ? " selected" : "";
                        html += '<option value="'+item.id+'"'+selected+'>'+item.name+'</option>';
                    });
                    $("#county").html(html);
                }
            });
        }
		
		function validateForm(){
			$('#spaceForm').bootstrapValidator({
				feedbackIcons: {
            　　　　　　　　		valid: 'glyphicon glyphicon-ok',
            　　　　　　　　		//invalid: 'glyphicon glyphicon-remove',
            　　　　　　　　		validating: 'glyphicon glyphicon-refresh'
        　　　　　　　　 	},
	            fields: {
	            	name: {
	                    validators: {
	                        notEmpty: {
	                            message: '空间名称不能为空'
	                        }
	                    }
	                },
                    area: {
	                    validators: {
	                        notEmpty: {
	                            message: '运营面积不能为空'
	                        },
	                        numeric: {
	                        	message: '运营面积必须为数字'
	                        }
	                    }
	                },
                    station_open_price: {
                        validators: {
                            notEmpty: {
                                message: '开放工位价格不能为空'
                            },
                            numeric: {
                                message: '开放工位价格必须为数字'
                            }
                        }
                    },
                    station_close_price: {
                        validators: {
                            notEmpty: {
                                message: '封闭工位价格不能为空'
                            },
                            numeric: {
                                message: '封闭工位价格必须为数字'
                            }
                        }
                    },
                    address: {
                        validators: {
                            notEmpty: {
                                message: '详细地址不能为空'
                            }
                        }
                    },
                    phone: {
                        validators: {
                            notEmpty: {
                                message: '联系电话不能为空'
                            }
                        }
                    },
                    account_name_tax: {
                        validators: {
                            notEmpty: {
                                message: '含税收款账户名称不能为空'
                            }
                        }
                    },
                    bank_card_id_tax: {
                        validators: {
                            notEmpty: {
                                message: '含税收款账号不能为空'
                            },
                            numeric: {
                                message: '含税收款账号必须为数字'
                            }
                        }
                    },
                    bank_name_tax: {
                        validators: {
                            notEmpty: {
                                message: '含税收款账户开户行不能为空'
                            }
                        }
                    },
                    account_name: {
                        validators: {
                            notEmpty: {
                                message: '不含税收款账户名称不能为空'
                            }
                        }
                    },
                    bank_card_id: {
                        validators: {
                            notEmpty: {
                                message: '不含税收款账号不能为空'
                            },
                            numeric: {
                                message: '不含税收款账号必须为数字'
                            }
                        }
                    },
                    bank_name: {
                        validators: {
                            notEmpty: {
                                message: '不含税收款账户开户行不能为空'
                            }
                        }
                    },
	            }
	        });
			var data = $('#spaceForm').data('bootstrapValidator');
		    if (data) {
		        data.validate();
		        if (!data.isValid()) {
		            return false;
		        }
		    }
		    return true;
		}
	</script>
</body>
</html>